<!-- 使用登记详情 -->
<template>
  <div class="useReg-detail animate__animated animate__zoomIn">
    <div v-if="!loadingFlag" class="useReg-detail-top">
      <dv-decoration-11 style="width: 30%; height: 50%; font-size: 0.3rem"
        >使用登记综合信息</dv-decoration-11
      >
      <div class="goback">
        <GoBack></GoBack>
      </div>
      <div class="goindex">
        <GoIndex></GoIndex>
      </div>
    </div>
    <div v-if="!loadingFlag" class="useReg-main">
      <ul>
        <div class="box box1">
          <li v-for="(item, i) in head1" :key="i">
            <div class="li-box">
              <p>
                <span>{{ item.name }}</span>
              </p>
              <p>
                <span>{{ useRegDetail[item.prop] || '--' }}</span>
              </p>
            </div>
          </li>
        </div>
        <div class="box box2">
          <li v-for="(item, i) in head2" :key="i">
            <div class="li-box">
              <p>
                <span>{{ item.name }}</span>
              </p>
              <p>
                <span v-if="item.prop=='p3'" class="link-blue" @click="toUnitDetail(useRegDetail['id'])">{{ useRegDetail[item.prop] || '--' }}</span>
                <span v-else>{{ useRegDetail[item.prop] || '--' }}</span>
              </p>
            </div>
          </li>
        </div>
        <div class="box box3">
          <li v-for="(item, i) in head3" :key="i">
            <div class="li-box">
              <p>
                <span>{{ item.name }}</span>
              </p>
              <p>
                <span>{{ useRegDetail[item.prop] || '--' }}</span>
              </p>
            </div>
          </li>
        </div>
        <div class="box box4">
          <li v-for="(item, i) in head4" :key="i">
            <div class="li-box">
              <p>
                <span>{{ item.name }}</span>
              </p>
              <p>
                <span>{{ useRegDetail[item.prop] || '--' }}</span>
              </p>
            </div>
          </li>
        </div>
      </ul>
    </div>
    <!-- loading -->
    <div v-if="loadingFlag" class="e-loading">
      <dv-loading style="color: #fff; opcity: 0.5"
        >数据加载中...</dv-loading
      >
    </div>
  </div>
</template>

<script>
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      loadingFlag: true,
      head1: [
        { name: "登记类别", prop: "p1" },
        { name: "产品名称", prop: "p2" },
      ],
      head2: [
        { name: "使用单位名称", prop: "p3" },
        { name: "使用单位地址", prop: "p4" },
        { name: "设备使用地点", prop: "p5" },
        { name: "使用单位统一社会信用代码", prop: "p6" },
        { name: "单位固定电话", prop: "p7" },
        { name: "邮政编码", prop: "p8" },
        { name: "移动电话", prop: "p9" },
      ],
      head3: [
        { name: "使用单位填表人员", prop: "p10" },
        { name: "日期", prop: "p11" },
        { name: "使用单位安全管理人员", prop: "p12" },
        { name: "日期", prop: "p13" },
      ],
      head4: [
        { name: "登记机关登记人员", prop: "p14" },
        { name: "日期", prop: "p15" },
        { name: "使用登记证编号", prop: "p16" },
      ],

      useRegDetail: {
        p1: "--",
        p2: "--",
        p3: "--",
        p4: "--",
        p5: "--",
        p6: "--",
        p7: "--",
        p8: "--",
      },
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    toUnitDetail (id) {
      // return console.log(id);
      this.$router.push({
        name: 'companyList-detail',
        params: {id}
      })
    },
    async init() {
      let id = this.$route.params.id;
      console.log('id: ' + id);
      let params = {id}

      let ret = await this.$http.postGetOperRegDetail(params)
      if (ret.data.errorCode != 0) {
        return console.log('使用登记后台报错');
      }
      let data = ret.data.data
      console.log(data);

      this.useRegDetail = {
        p1: data.toldDetail.type,
        p2: data.toldDetail.reg_dev_name,
        p3: data.toldDetail.use_com_name,
        p4: data.toldDetail.type1,
        p5: data.toldDetail.dev_use_address,
        p6: data.toldDetail.use_org_no,
        p7: data.toldDetail.com_phone,
        p8: data.toldDetail.zip,
        p9: data.toldDetail.lxr_phone,
        p10: data.toldDetail.write_name,
        p11: data.toldDetail.write_date,
        p12: data.toldDetail.write_safe_name,
        p13: data.toldDetail.write_safe_date,
        p14: data.toldDetail.registration_name,
        p15: data.toldDetail.registration_date,
        p16: data.toldDetail.registration_code,
        id: data.toldDetail.use_com_id
      }

      // console.log(this.useRegDetail);

      this.loadingFlag = false
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.init()
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  beforeRouteEnter(to,form,next) {
    if (JSON.stringify(to.params)=="{}") {
      to.meta.isBack = true
    }else{
      to.meta.isBack = false
    }
    next()
  },
  activated() {
    if (!this.$route.meta.isBack) {
      console.log('需要刷新');
      this.init()
    }else{
      console.log('缓存页面');
    }
  },
};
</script>

<style lang="less" scoped>
.useReg-detail {
  width: 100%;
  height: 100%;
  .useReg-detail-top {
    width: 100%;
    height: 15%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    color: @FontColor;
    .goback {
      position: absolute;
      left: 0;
      top: 2%;
    }
  }
  .useReg-main {
    width: 100%;
    height: 85%;
    ul {
      width: 70%;
      height: 100%;
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      .box {
          display: flex;
          flex-wrap: wrap;
        background-color: rgba(245, 245, 245, .8);
        border-radius: 0.05rem;
          margin: 0.6% 0;
          li {
            width: 50%;
            height: 20%;
            display: flex;
            justify-content: center;
            align-items: center;
            .li-box {
            width: 90%;
            height: 80%;
            display: flex;
            border-radius: 0.04rem;
            overflow: hidden;
            p {
                width: 40%;
                height: 100%;
                display: flex;
                justify-content: center;
                align-items: center;
                // background-color: rgba(77, 144, 254, 0.5);
                span {
                font-size: 0.2rem;
                color: @Blue;
                font-weight: 700;
                }
            }
            p:last-child {
                width: 60%;
                span {
                    color: #555;
                }
                // background-color: rgba(128, 195, 66, 0.7);
            }
            }
        }
      }
      .box1 {
          flex: 1;
          li {
              height: 100%;
          }
      }
      .box2 {
          flex: 4;
        //   background-color: rgba(77, 144, 254, 0.2);
          li {
              height: 25%;
          }
      }
      .box3 {
          flex: 2;
          li {
              height: 50%;
          }
      }
      .box4 {
          flex: 2;
        //   background-color: rgba(77, 144, 254, 0.2);
          li {
              height: 50%;
          }
      }
      
    }
  }
}
</style>